import time

from selenium.webdriver.common.by import By

from Base.BasePage import BasePage


class OpenAccount(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver
        # 点击开户登录
        # self.openAccount = (By.XPATH, '//*[@id="mlayout"]/div[2]/div[3]/div/div[1]/div/a')
        # 点击开户 注册
        self.openAccount = (By.XPATH, '//*[@id="step3"]/div/div/div/div/a')
        # 开户
        self.realName = (By.XPATH, '//*[@id="safeName"]/div[2]/input')
        self.idCard = (By.XPATH, '//*[@id="safeName"]/div[3]/input')
        self.button = (By.CLASS_NAME, "btn")
        # 立即开通
        self.nowOpen = (By.XPATH, '//*[@id="successForm"]/input')
        # 我已知晓
        self.finish = (By.XPATH, '//*[@id="xuboxPageHtml1"]/div/div/a[1]')
        self.assert_success1 = (By.XPATH, '/html/body')

    def open_account(self, realName, idCard):
        self.click_element(self.openAccount)
        self.base_clear_input(self.realName, realName)
        self.base_clear_input(self.idCard, idCard)
        self.click_element(self.button)

    def now_open_account(self):
        time.sleep(2)
        self.get_element(self.nowOpen).click()

    def assert_success_openAcount(self):
        # 开通账户成功的断言
        result = self.switch_window(self.assert_success1).text
        return result

    def assert_fail_openAcount(self):
        pass
